package com.tri.framework;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

public class SpriteAnimation  extends GraphicObject
{
	private Rect mSRectangel;
	private int mFPS;
	private int mNoOfFrames;
	private int mCurrentFrame;
	private long mFrameTimer;
	private int mSpriteHeight;
	private int mSpriteWidth;
	
	public SpriteAnimation(Bitmap bitmap)
	{
		super(bitmap);
		mSRectangel = new Rect(0, 0, 0, 0);
		mFrameTimer = 0;
		mCurrentFrame = 0;
	}
	
	public void initSpriteData(int height , int width, int theFPS, int theFrameCount)
	{
		mSpriteHeight = height;
		mSpriteWidth = width;
		mSRectangel.top = 0;
		mSRectangel.bottom = mSpriteHeight;
		mSRectangel.left = 0;
		mSRectangel.right = mSpriteWidth;
		mFPS = 1000/theFPS;
		mNoOfFrames = theFrameCount;
	}
	
	public void Draw(Canvas canvas)
	{
		Rect dest = new Rect(m_x, m_y, m_x + mSpriteWidth, m_y + mSpriteHeight);
		canvas.drawBitmap(m_bitmap, mSRectangel, dest, null);
	}
	
	public void update(long gameTime)
	{
		if(gameTime > mFrameTimer + mFPS)
		{
			mFrameTimer = gameTime;
			mCurrentFrame += 1;
			if(mCurrentFrame >= mNoOfFrames)
				mCurrentFrame = 0;
		}
		mSRectangel.left = mCurrentFrame * mSpriteWidth;
		mSRectangel.right = mSRectangel.left + mSpriteWidth;
	}
		
}
